import { createRouter, createWebHashHistory } from 'vue-router'
//import HomeView from '../views/HomeView.vue'

const routes = [
 
  
  {
    path: '/',
    name: '',
    component: () => import('../views/login/index')
  },
  {
    path: '/r',
    name: 'r',
    component: () => import('../views/login/reg')
  },
  {
    path: '/manageLayout',
    name: 'manageLayout',
    component: () => import('../views/Layout/manageLayout')
  },
  {
    path: '/commonLayout',
    name: 'commonLayout',
    component: () => import('../views/Layout/commonLayout')
  },
  {
    path: '/commonRoom',
    name: 'commonRoom',
    component: () => import('../views/Room/commonRoom')
  },
  {
    path: '/manageRoom',
    name: 'manageRoom',
    component: () => import('../views/Room/manageRoom')
  },
  {
    path: '/commonUser',
    name: 'commonUser',
    component: () => import('../views/User/commonUser')
  },
  {
    path: '/manageUser',
    name: 'manageUser',
    component: () => import('../views/User/manageUser')
  },
  {
    path: '/commonMeeting',
    name: 'commonMeeting',
    component: () => import('../views/Meeting/commonMeeting')
  },
  {
    path: '/manageMeeting',
    name: 'manageMeeting',
    component: () => import('../views/Meeting/manageMeeting')
  },
  {
    path: '/myMeeting',
    name: 'myMeeting',
    component: () => import('../views/Meeting/myMeeting')
  },
  {
    path: '/mainLayout',
    name: 'mainLayout',
    component: () => import('../views/Layout/mainLayout')
  },
  {
    path: '/infoLayout',
    name: 'infoLayout',
    component: () => import('../views/Layout/infoLayout')
  },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

export default router

router.beforeEach((to,from,next)=>{
  if(to.path ==='/' || to.path ==='/r'){
   
    next();
  }else{
    
    const storedUserID = localStorage.getItem('userID');
    console.log(storedUserID)
    storedUserID?next():next('/r')
  
  }
})
